<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>详情</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div>
          <el-row :gutter="20">
            <el-col :sm="24" :lg="24">
              <div class="tab-box">
                <h2 class="title-box">Gateway001</h2>
                <p class="small-title">Details of the hardware</p>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :sm="24" :lg="24">
              <div class="tab-box">
                <div class="tab-box-line">
<!--                  <span @click="tanLine=1" :class="{active:tanLine==1}">Details</span>-->
                  <span @click="tanLine=2" :class="{active:tanLine==2}">Warning</span>
                  <span @click="tanLine=3" :class="{active:tanLine==3}">Setting</span>
                  <span @click="tanLine=4" :class="{active:tanLine==4}">Rule</span>
                </div>
              </div>
            </el-col>
          </el-row>
          <tabDetail v-if="tanLine==1"></tabDetail>
          <tabWarning v-if="tanLine==2"></tabWarning>
          <tabSetting v-if="tanLine==3" @showDetailJson="showDetailJson"></tabSetting>
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button size="small" @click="closePOpup">cancel</el-button>
        <el-button size="small" type="primary" @click="closePOpup">ok</el-button>
      </div>
    </div>
    <deviceDetail :visible.sync="showJsonvisible"></deviceDetail>
  </div>
</template>

<script>

import tabDetail from "./tabDetail";
import tabWarning from "./tabWarning";
import tabSetting from "./tabSetting";
import deviceDetail from "./deviceDetail";

export default {
  props: ['visible'],
  name: "boxDetail",
  components: {tabDetail, tabWarning, tabSetting, deviceDetail},
  data() {
    return {
      showJsonvisible: false,
      dialogVisible: false,
      jsonList: [
        {
          key_name: '',
          value_name: '',
          type: 2,
          list: []
        }
      ],
      tanLine: 2
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    showDetailJson() {
      this.showJsonvisible = true
    },
    addList(option) {
      if (option === 'init') {
        this.jsonList.push({
          key_name: '',
          value_name: '',
          type: 1,
          list: []
        })
      }
    },
    deleteList(index) {
      this.jsonList.splice(index, 1)
    },
    addSmallList(index) {
      this.jsonList[index].list.push({
        key_name: '',
        value_name: '',
        type: 1,
        list: []
      })
    },
    deleteSmallList(index, small) {
      this.jsonList[index].list.splice(small, 1)
    },
    saveJsonFn() {
      console.log('jsonList:', this.jsonList)
      let data_ = {}
      for (let item of this.jsonList) {
        if (item.type === 1) {
          data_[item.key_name] = item.value_name
        } else {
          let smallJson = {}
          for (let small_ of item.list) {
            smallJson[small_.key_name] = small_.value_name
          }
          data_[item.key_name] = smallJson
        }
      }
      console.log('data_:', JSON.stringify(data_))
    },
    closePOpup() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style scoped>
.Json-list {
  border: 1px solid #eee;
  padding: 10px;
}

.Json-list-line {
  display: flex;
  align-items: center;
}

.w-150 {
  width: 150px;
}

.ml-10 {
  margin-left: 10px;
}

.mr-10 {
  margin-right: 10px;
}

.mb-10 {
  margin-bottom: 10px;
}

#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.cornerComment-in {
  width: 80%;
  height: 80%;
  background: rgba(245, 246, 250, 1);
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  overflow: hidden;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
  background: #fff;

}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
  background: #fff;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.tab-box {
  background: #fff;
  padding: 10px;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1);
  border: 1px solid #e6ebf5;
  margin-bottom: 10px;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  padding-left: 20px;
}

.tab-box-line {
  display: flex;
  align-items: center;
}

.tab-box-line span {
  padding: 10px 5px;
  margin-right: 30px;
  display: block;
  cursor: pointer;
}

.tab-box-line span.active {
  color: #00afff;
  border-bottom: 3px solid #00afff;
}

.title-box {
  margin: 10px 0;
}

.small-title {
  margin: 0;
}
</style>
<!--<h2 class="title-box">Gateway001</h2>-->
<!--<p class="small-title">Details of the hardware</p>-->
